Fix: guard resetPersistence when not initialized in syncState.reset #627
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
When syncStateValue.reset() is called early (before loadLocal initializes persistence), resetPersistence is still undefined. reset() calls syncStateValue.resetPersistence() unconditionally, which throws:
TypeError: syncStateValue.resetPersistence is not a function (it is undefined).
Steps to reproduce
Call syncState(obs).reset() immediately after creating a synced observable.
In async persistence setups, reset can run before loadLocal finishes.
Root cause
resetPersistence is only assigned inside loadLocal(...). Until then it’s undefined, but reset() calls it without a guard.
Change
Replace the direct call with a safe optional call and fallback.
How this fixes it
Prevents the exception and allows reset() to work even when called before persistence initialization, without changing behavior once resetPersistence exists.
Patch
Notes
This is backward-compatible and no-op when persistence has already been initialized.
If you want me to retry PR creation with a different auth method, tell me what you prefer.